﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="Phoenix.Common.Util" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    商品类目首页</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="HeadScripts" runat="server">
    <script type="text/javascript" src="/Scripts/m-lhgdialog/m-lhgdialog.js"></script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <div class="path">
        <a href="#"><strong>类目管理</strong></a>
    </div>
    <div class="pd10">
        <div class="mb10 aR">
            <a href="javascript:;" title="新增" class="a-btn1" onclick="OpenPop('/News/CatalogEdit?pid=<%=ViewData["parentID"] %>', '新增商品类目',500,250)">新增</a> <a href="/Views/Category/index.aspx" title="返回大类" class="a-btn1">返回</a>
            <input id="pid" name="pid" type="hidden" value="" />
        </div>
        <span id="Grid">
            <table class="tb-list hover">
                <tr>
                    <th>
                        分类编号
                    </th>
                    <th>
                        分类名称
                    </th>
                    <th>
                        排序值
                    </th>
                    <th>
                        级别
                    </th>
                     <th>
                        创建时间
                    </th>
                    <th>
                        更新时间
                    </th>
                    <th width="20%">
                        操作
                    </th>
                </tr>

                <% foreach (Phoenix.Service.Model.NewsCatalogModel item in ViewData["CatalogList"] as List<Phoenix.Service.Model.NewsCatalogModel> ) %>
                <%{%>
                <tr>
                    <td>
                        <%=item.CatalogID %>
                    </td>
                    <td>
                        <a href="/Views/Category/index.aspx?pid=<%=item.CatalogID %>">
                            <%=item.CatalogName %></a>
                    </td>
                    <td>
                        <%=item.SortOrder %>
                    </td>
                    <td>
                       
                    </td>
                    <td>
                        <%=item.CreateTime.ToString("yyyy-MM-dd")%>
                    </td>
                    <td>
                        <%=item.UpdateTime.ToString("yyyy-MM-dd")%>
                    </td>
                    <td>
                        <a href="javascript:void(showEdit('<%=item.CatalogID %>'))">编辑</a> <a href="javascript:;" onclick="DeleteCategory('<%=item.CatalogID %>')">删除</a>
                        <% if (item.IsLeaf) %>
                        <%{%>
                        <a href="/Views/Category/index.aspx?pid=<%=item.CatalogID %>">子类目</a>
                        <%}%>
                    </td>
                </tr>
                <%}%>
            </table>
        </span>
        <!-- 分页插件  -->
        <div id="pager" class="aR mt10">
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="BodyScripts" runat="server">
    <script type="text/javascript" src="/Scripts/library/m-pagination.js"></script>
    <script type="text/javascript">
        (function () {
            pagerInit();
        })(jQuery);

        // 初始化分页插件
        function pagerInit(recordCount) {
            // 该分页为每次查询的ajax调用后获得的记数最大数，放在Grid.ascx
            var recordCount = parseInt($("#__recordCount__").text());

            $('#pager').pagination(recordCount, {
                fCallBack: pagerCallBack, // 回调方法
                nPageSize: 20, 			// 显示分页项数
                nDisplayItem: 5, 		// 一个分页显示的数据量
                nStartEndItem: 2, 		// 特长分页首尾显示分页项数
                nPageIndex: 0
            });

            // 分页回调
            function pagerCallBack(pageIndex, jq) {
                search(pageIndex);
            };
        };

        // 搜索
        function search(pageIndex) {
            var pIndex = 0;
            if (pageIndex !== undefined) {
                pIndex = pageIndex;
            }

            $.ajax({
                url: "/Views/Category/Index.aspx?pageIndex=" + pIndex,
                data: { "pid": $("#pid").val() },
                type: 'POST',
                success: function (data) {
                    // 填充数据

                    // 设置表格样式(调用全局方法)
                    TableHover();

                    // 当重新搜索时，重置分页
                    if (pIndex === 0) {
                        pagerInit();
                    }
                },
                error: function (XmlHttpRequest, textStatus, errorThrown) {
                    alert(errorThrown);
                }
            });
        };

        // 刷新列表
        function refresh() {
            var pageIndex = parseInt($("div.pagination>span.page").attr("title"));
            search(pageIndex - 1);
        };

        // 删除类目
        function DeleteCategory(categoryID) {
            if (confirm("确认删除吗?") == false) {
                return;
            }

            $.ajax({
                url: "/Views/Category/Delete.ashx",
                data: { "categoryID": categoryID },
                type: "POST",
                success: function (data, textStatus) {
                    if (data.status === "warning" || data.status === "error") {
                        alert(data.msg);
                        return false;
                    }
                    // 刷新列表
                    refresh();
                },
                error: function (XmlHttpRequest, textStatus, errorThrown) {
                    alert(errorThrown);
                }
            });
        };

        // 显示编辑
        function showEdit(cid, pid) {
        	OpenPop('/News/CatalogEdit?cid=' + cid , "编辑商品类目", 500, 250);
        };

        //打开弹窗
        function OpenPop(url, titleName, width, height) {
            width = width || 800;
            height = height || 500;
            window.top.winObj = window;
            window.top.oDG = new $.dialog({ id: 'esDialog', title: titleName, page: url, width: width, height: height, btnBar: false, lockScroll: true });
            window.top.oDG.ShowDialog();
        }
        
    </script>
</asp:Content>
